package com.kingdee.eas.hr.emp.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.hr.affair.contract.LongContractEvalEntryFactory;
import com.kingdee.eas.custom.hr.affair.contract.LongContractEvalEntryInfo;
import com.kingdee.eas.custom.hr.affair.contract.ServiceContractEvalEntryFactory;
import com.kingdee.eas.custom.hr.affair.contract.ServiceContractEvalEntryInfo;
import com.kingdee.eas.custom.hr.affair.contract.ShortContractEvalEntryFactory;
import com.kingdee.eas.custom.hr.affair.contract.ShortContractEvalEntryInfo;
import com.kingdee.eas.custom.hr.affair.contract.StatusEnum;
import com.kingdee.eas.hr.emp.EmployeeContractInfo;

public class EmployeeContractControllerBeanEx extends
		EmployeeContractControllerBean {

	@Override
	protected void _batchProcessContracts(Context ctx, IObjectCollection cols,
			int type) throws BOSException, EASBizException {
		EmployeeContractInfo info = null;

		for (int i = 0; i < cols.size(); i++) {
			info = (EmployeeContractInfo) cols.getObject(i);
			Object obj = info.get("EVALENTRY");
			if (obj != null) {

				if (obj instanceof LongContractEvalEntryInfo) {
					LongContractEvalEntryInfo entry = (LongContractEvalEntryInfo) obj;
					entry.setStatus(StatusEnum.DO);
					LongContractEvalEntryFactory.getLocalInstance(ctx)
							.updatePartial(entry,
									this.getSelectorItemCollection());

				} else if (obj instanceof ShortContractEvalEntryInfo) {
					ShortContractEvalEntryInfo entry = (ShortContractEvalEntryInfo) obj;
					entry.setStatus(StatusEnum.DO);
					ShortContractEvalEntryFactory.getLocalInstance(ctx)
							.updatePartial(entry,
									this.getSelectorItemCollection());

				} else if (obj instanceof ServiceContractEvalEntryInfo) {
					ServiceContractEvalEntryInfo entry = (ServiceContractEvalEntryInfo) obj;
					entry.setStatus(StatusEnum.DO);
					ServiceContractEvalEntryFactory.getLocalInstance(ctx)
							.updatePartial(entry,
									this.getSelectorItemCollection());

				}
			}
			// if (info.isIsContinuousSigned()) {
			// info.setContinuousSignedCount(info.getContinuousSignedCount() +
			// 1);
			// }
		}

		super._batchProcessContracts(ctx, cols, type);
	}

	private SelectorItemCollection getSelectorItemCollection() {
		SelectorItemCollection selectors = new SelectorItemCollection();
		selectors.add("status");
		return selectors;
	}
}
